using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using SExperiment;

namespace Converters
{
	public class TargetFilterMultiConverter : IMultiValueConverter
	{
		public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
		{
			if (values != null && values.Length == 2 && values[0] != null && values[0] != DependencyProperty.UnsetValue && values[1] != null && values[1] != DependencyProperty.UnsetValue && values[0] is int && values[1] is ObservableCollection<SampleTargetItem>)
			{
				int tubeNo = 1;
				int.TryParse(values[0].ToString(), out tubeNo);
				ObservableCollection<SampleTargetItem> source = values[1] as ObservableCollection<SampleTargetItem>;
				return source.Where((SampleTargetItem s) => s.TubeNo == tubeNo);
			}
			return "";
		}

		public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
		{
			return null;
		}
	}
}
